package cn.tedu.springdemo.day07;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * DI学习依赖注入：创建bean时候给属性赋值（所谓的注入）
 * @Value注解：使用在私有属性上，DI依赖注入操作
 * 语法：@Value("写死/写活")
 */
@Component
public class Demo {
    @Value("${name}")//properties文件取值  ${key}
    private String name;//xml:<property  id="name" value="孙玉玺">
    @Value("${age}")//properties文件取值  ${key}
    private int age;
    @Value("#{@list1}")//list私有属性，第一步：xml完成配置并且id属性 第二步#{@id值}
    private List<String> List;
    @Value("#{@set1}")
    private Set<String>set;
    @Value("#{@map1}")
    private Map<String,Object> map;
    @Value("#{@properties1}")
    private Properties properties;//JDBC--xml解析配置文件{key,value}
//私有属性-----引用类型对象Pig对象---作为属性
    @Autowired//@Autowired 自动装配注解---重点知道装配流程
    @Qualifier("p")  //等同于byName属性值：按照id方式 指定id=p
    private Pig pig;//byName理解：id方式  byType：class方式
    public Pig getPig(){return pig;}

    @Override
    public String toString() {
        return "Demo{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", List=" + List +
                ", set=" + set +
                ", map=" + map +
                ", properties=" + properties +
                ", pig=" + pig +
                '}';
    }

    public void setPig(Pig pig) {
        this.pig = pig;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public java.util.List<String> getList() {
        return List;
    }

    public void setList(java.util.List<String> list) {
        List = list;
    }

    public Set<String> getSet() {
        return set;
    }

    public void setSet(Set<String> set) {
        this.set = set;
    }

    public Map<String, Object> getMap() {
        return map;
    }

    public void setMap(Map<String, Object> map) {
        this.map = map;
    }

    public Properties getProperties() {
        return properties;
    }

    public void setProperties(Properties properties) {
        this.properties = properties;
    }


}
